<!DOCTYPE html>
<html>
<#include "/views/ftl/base/manager_include.ftl">
<script type="text/javascript" src="${basePath}js/My97DatePicker/WdatePicker.js"></script>
<base href="${basePath}">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用餐座位</title>
<script src="${basePath}css/jquery-ui.js"></script>
<link rel="stylesheet" href="${basePath}css/jquery-ui.css" />
    <!--     <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
		<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />-->
</head>
<body style="background:#eef3f7;">
<#include "/views/ftl/base/head.ftl"> 
<div class="Main">
  <div class="dw">
<#include "/views/ftl/base/menu.ftl">
<#function a><#return "用餐位置列表_List"></#function>
<!--右边内容-->
<div class="Rightbox fl">
    <!--导航-->
    <div class="Bread_crbs clear">
      <div class="Bread_crbs_img fl"></div>
      <div class="Bread_crbs_text fl">
      	<a href="javascript:void(0);"><span>用餐座位</span></a>
      	<span class="fnt_famy">></span>
      	<a href="javascript:void(0);"><span>用餐座位列表</span></a>
      </div>
    </div>
      <div class="Table">
        </div>
  <!--表格列表-->




    <div class="fl">

        <div class="input_name" style="height:32px;margin-bottom: 20px;">
            <span class="left_title"  >位置名称：</span>
            <input type="text" name="locationName"  class="search_text tdd50" style="width:210px" value="">
        </div>

        <div class="input_name" style="height:32px;margin-bottom: 20px;">
            <span class="left_title"  >位置类型：</span>
            <select id="locationType"   class="sp" style="width: 220px;">
			<#list mealLocationTypeEnum as enum>
                <option value="${enum.type}" >${enum.typeName}</option>
			</#list>
            </select>
        </div>

        <a style="margin-left: 220px;" id="save" class="yg-btn yg-btn-primary" href="javascript:void(0);"><span  >保存</span></a>

    </div>
        

        
</div>
</div> 
<div style="display:none;">
<intpu type="hidden" value="${(goods.firstGoodsCategoryId)?c}" />

</div>
<script>

$(function(){

	
	
	loadfirstGoodsCategoryList();
	function loadfirstGoodsCategoryList(){
		$.ajax({
			url : "${basePath}manager/GoodsCategory_goodsCategoryList",
			data : { 
				pageNumber:1,
				pageSize:100
			}, 
			dataType :"JSON",
			cache : false, 
			type : "POST",
			success : function(dat){
				if(dat.code==1){
					 var html ='';
					 html+='<option value="">----</option>';
					 $(dat.data).each(function(index,bean){  
					 	if(bean.id =='${(goods.firstGoodsCategoryId)?c}'){
					 		html+='<option value="'+bean.id+'" selected="selected"  >'+bean.categoryName+'</option> '; 
					 	}else{
					 		html+='<option value="'+bean.id+'"  >'+bean.categoryName+'</option> '; 
					 	}
					 	
					 });
					 $('#first_goods_category_list_select').html(html);
				} 
			}
		}); 
		
		loadSecondGoodsCategoryList('${(goods.firstGoodsCategoryId)?c}','${((goods.secondGoodsCategoryId)?c)!''}');
		
	}
	
	 $('#first_goods_category_list_select').change(function(){
	 	var parentId=$('#first_goods_category_list_select').val();
	 	loadSecondGoodsCategoryList(parentId);
	 	
	 	var goodsCategoryId =$('#first_goods_category_list_select').find("option:selected").val();
	 	var goodsName=$('#first_goods_category_list_select').find("option:selected").text();
	 	if(goodsCategoryId==''){
	 		$('input[name=goodsName]').val('');
	 	}else{
	 		$('input[name=goodsName]').val(goodsName);
	 	}
	 	
	 	
	 });
	 
	 $('#second_goods_category_list_select').change(function(){
	 	
	 	var goodsName= $('#second_goods_category_list_select').find("option:selected").text();
	 	var goodsCategoryId =$('#second_goods_category_list_select').val();
	 	if(goodsCategoryId==''){
	 		goodsName=$('#first_goods_category_list_select').find("option:selected").text();
	 		$('input[name=goodsName]').val(goodsName);
	 	}else{
	 		$('input[name=goodsName]').val(goodsName);
	 	}
	 	
	 });
	
	function loadSecondGoodsCategoryList(parentGoodsCategoryId,secondGoodsCategoryId){
		if('' == parentGoodsCategoryId){
			var html ='';
			html+='<option value="">----</option>';
			$('#second_goods_category_list_select').html(html);
			return ;
		}
	
		$.ajax({
			url : "${basePath}manager/GoodsCategory_goodsCategoryList",
			data : { 
				goodsCategoryParentId:parentGoodsCategoryId,
				pageNumber:1,
				pageSize:100
			}, 
			dataType :"JSON",
			cache : false, 
			type : "POST",
			success : function(dat){
				if(dat.code==1){
					 var html ='';
					 html+='<option value="">----</option>';
					 $(dat.data).each(function(index,bean){ 
					 	if(secondGoodsCategoryId=='undefined' || null ==secondGoodsCategoryId  || '' ==secondGoodsCategoryId ){ 
					 		html+='<option value="'+bean.id+'">'+bean.categoryName+'</option> '; 
					 	}else{
					 		
					 		if(secondGoodsCategoryId==bean.id){
					 			html+='<option value="'+bean.id+'"  selected="selected">'+bean.categoryName+'</option> '; 
					 		}else{
					 			html+='<option value="'+bean.id+'">'+bean.categoryName+'</option> '; 
					 		}
					 	}
					 	
					 });
					 $('#second_goods_category_list_select').html(html);
				} 
			}
		});
		
	
	}
	
	//加载品牌
	loadBrandList();
	function loadBrandList(){
		$.ajax({ 
			url : "${basePath}manager/Brand_brandList",
			data : { 
				pageNumber:1,
				pageSize:100
			}, 
			dataType :"JSON",
			cache : false, 
			type : "POST",
			success : function(dat){
				if(dat.code==1){
					 var html ='';
					 html+='<option value="">----</option>';
					 $(dat.data).each(function(index,bean){
					 	if(bean.id == '${(goods.brandId)?c}'){
					 		html+='<option value="'+bean.id+'" selected="selected">'+bean.brandName+'</option> '; 
					 	}else{
					 		html+='<option value="'+bean.id+'">'+bean.brandName+'</option> '; 
					 	}
					 	
					 });
					 $('#brand_list_select').html(html);
				} 
			}
		}); 
	}
 
	
	
	$("#modify").click(function(){
		
		var brandId = $('#brand_list_select').val();
		var first_goods_category_id = $('#first_goods_category_list_select').val();
		var second_goods_category_id = $('#second_goods_category_list_select').val();
		
		var goodsCategoryId =first_goods_category_id;
		if(second_goods_category_id!=''){
			goodsCategoryId=second_goods_category_id;
		}
		
		var goodsNumber=$("input[name=goodsNumber]").val();
		var goodsName=$("input[name=goodsName]").val();
		var retailPrice=$("input[name=retailPrice]").val();
		var unit=$("input[name=unit]").val();//
		var year=$("input[name=year]").val();//
		var season=$("select[name=season]").val();//
		var applySex=$("select[name=applySex]").val();
		var goodsRemark=$("input[name=goodsRemark]").val();//
		
		if(brandId==''){
			alert("请选择品牌");
			return;
		}
		if(goodsCategoryId==''){
			alert("请选择分类分类");
			return;
		}
		if(goodsNumber==''){
			alert('产品号不能为空');
			return ;
		}
		if(goodsName==''){
			alert('产品名称不能为空');
			return ;
		}
		if(retailPrice==''){
			alert('价格不能为空');
			return ;
		}
		if(applySex==''){
			alert("请选择适用群体");
			return ;
		}
		
		$.ajax({ 
			url : "${basePath}manager/Goods_modifyGoods",
			data : { 
				goodsId:'${(goods.id)?c}',
				brandId:brandId,
				goodsCategoryId:goodsCategoryId,
				goodsNumber:goodsNumber,
				goodsName:goodsName,
				retailPrice:retailPrice,
				unit:unit,
				year:year,
				season:season,
				applySex:applySex,
				goodsRemark:goodsRemark
			}, 
			dataType :"JSON",
			cache : false, 
			type : "POST",
			success : function(dat){
				if(dat.code==1){
					alert(dat.msg);
					window.location.reload();
				}else{
					alert(dat.msg);	
				} 
			}
		});
	});
	
	//加载尺码类型
	loadSizeSpecificationList();
	function loadSizeSpecificationList(){
		$.ajax({ 
			url : "${basePath}manager/Specification_sizeSpecificationList",
			data : {
				
			},
			dataType :"JSON",
			cache : false, 
			type : "POST",
			success : function(dat){
				if(dat.code==1){
					 var html ='';
					 html+='<option value="">----</option>';
					 $(dat.data).each(function(index,bean){
					 	 html+='<option value="'+bean.id+'">'+bean.name+'</option>';
					 });
					 $("select[name='size_specification_select']").html(html);
					 
					 //显示
					 $("select[name='size_specification_select']").change(function(){ 
					     var sizeSpName = $(this).find("option:selected").text()
					 	 $.ajax({ 
							url : "${basePath}manager/Specification_specificationValueSearch",
							data : {
								 specificationName:sizeSpName
							},
							dataType :"JSON",
							cache : false, 
							type : "POST",
							success : function(dat2){
								$('#size_list_temp_div').html('');
								if(dat2.code==1){
									var html2="";
									//html2+='<span class="sp1">';
									//html2+='<span class="sp2"></span></span>';
									
									$(dat2.data).each(function(index,bean){
										html2+='<div data-sp-value="'+bean.value+'" data-sp-value-id="'+bean.id+'" class="bsp-alertdiv bsp-alertdiv-success dropzone_child"  style=" margin-right: 10px;     width: 50px;  padding: 5px;">';
										html2+='<span>'+bean.value+'</span>';
										//html2+='<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>';
										html2+='</div>'; 
									});
									$('#size_list_temp_div').html(html2);
									
								}
							}
						});  
					 });
					 //显示结束
					 
				}
			}
		}); 
	}
	
	function add_color_no_close(spId,spValue){  
		if(null!=spId &&   'undefined'!=spId){
			var html = ''; 
			var div_id = 'color_specification_div_'+spId;
			 
			 if($('#'+div_id).length>0){ 
			    return ;
			 }
			 var className ='color_specification';
			 
			 html+='<div id="'+div_id+'" class="bsp-alertdiv bsp-alertdiv-success dropzone_child '+className+'_div" data-specification-value-id="'+spId+'"  style=" margin-right: 10px;  width:120px; padding: 5px;">';
			 html+='<span>'+spValue+'</span>';
			 //html+='<button type="button" class="close '+className+'" data-parent-id="'+div_id+'" data-dismiss="alert" aria-hidden="true">×</button>';
			 html+='</div>';
			 $('#color_list_div').append(html);
		} 
	}
	
	function add_size_no_close(spId,spValue){
  		if(null!=spId &&   'undefined'!=spId){
  			var html = ''; 
  	  		var div_id = 'size_specification_div_'+spId;  
  	  		var className ='size_specification';
			if($('#'+div_id).length<=0){
				html+='<div id="'+div_id+'" class="bsp-alertdiv bsp-alertdiv-success dropzone_child '+className+'_div" data-specification-value-id="'+spId+'"  style=" margin-right: 10px;  width:120px; padding: 5px;">';
				html+='<span>'+spValue+'</span>';
				//html+='<button type="button" class="close '+className+'" data-parent-id="'+div_id+'" data-dismiss="alert" aria-hidden="true">×</button>';
				html+='</div>'; 
				$('#size_list_div').append(html);
			}
  		} 
  	}
	
		//加载产品
		loadProductList();
		function loadProductList(){ 
			$.ajax({ 
				url : "${basePath}manager/Product_productListByGoods",
				data : { 
					goodsId:'${(goods.id)?c}'
				}, 
				dataType :"JSON",
				cache : false, 
				type : "POST",
				success : function(dat){
					if(dat.code==1){
						var html ='';
						$(dat.data).each(function(index,bean){
							var color_v="";
							var size_v="";
							$(bean.specificationList).each(function(index2,bean2){
								 
								try{
									if('颜色'==bean2.name){
										add_color_no_close(bean2.specificationValueId,bean2.value);
										color_v=bean2.value;
									}
									if('尺码'==bean2.name){
										add_size_no_close(bean2.specificationValueId,bean2.value);
										size_v=bean2.value;
									} 
								}catch(e){
									alert(e);
								}
								
							});
							
							
							html+='<div id="product_div_'+bean.id+'" class="bsp-alertdiv bsp-alertdiv-success" data-product-id=""  >'; 
							html+='<div class="input_name" style="height:32px;margin-bottom: 20px;">';
							html+='<span class="left_title" style="line-height: 32px;">条码：</span>';
							html+='<input type="text" name="barCode" class="search_text tdd50" style="width:210px" value="'+bean.barCode+'" /> ';
							html+='<button type="button"  class=" close close_product" data-parent-id="product_div_'+bean.id+'" data-dismiss="alert" aria-hidden="true" style="margin-right: 600px;float: right;    font-size: 50px;">'+(index-0+1)+'</button>';
							html+='</div>';
							
							html+='<div class="input_name" style="height:32px;margin-bottom: 20px;">';
							html+='<span class="left_title" style="line-height: 32px;">颜色：</span>';
							html+='<input type="text" name="stockCount" class="search_text tdd50" style="width:210px;" value="'+color_v+'" /> ';
							//html+='<select name="color"   class="sp">';
							//html+='<option value="">---</option>';
							//html+='</select>';
							html+='</div>';
							
							html+='<div class="input_name" style="height:32px;margin-bottom: 20px;">'; 
							html+=' <span class="left_title" style="line-height: 32px;">尺码：</span>';
							html+='<input type="text" name="stockCount" class="search_text tdd50" style="width:210px;" value="'+size_v+'" /> ';
							//html+=' <select name="size"   class="sp">';
							//html+='<option value="">---</option>   ';
							//html+='</select>';
							html+='</div>';
							
							
							html+=' <div class="input_name" style="height:32px;margin-bottom: 20px;">';
							html+=' <span class="left_title" style="line-height: 32px;">库存：</span>';
					        html+='<input type="text" name="stockCount" class="search_text tdd50" style="width:210px;" value="'+bean.stockCount+'" /> ';
							html+='</div>';
							
							//html+='<span class="tbl_btn" style="margin-left: 290px;"> ';
							//html+='<span  type="button" class="bsp-btn bsp-btn-sm bsp-btn-primary" style="width: 100px;">保存</span> ';
							//html+=' </span>';
							
							html+='</div>'; 
						
						});

        	 
       					$('#div_product_list').html(html); 
         				
					}
				}
			}); 
		}


		//加载颜色规格
		var availableTags=new Array();
		var color_value_key = {};
		var color_key_value = {};
		loadColorSpecification();
		function loadColorSpecification() {
		  	var mycars=new Array();
		  	//async: false,
		    $.ajax({ 
					url : "${basePath}manager/Specification_specificationValueSearch",
					data : { 
						specificationName:'颜色'
					}, 
					dataType :"JSON",
					cache : false, 
					type : "POST", 
					success : function(dat){
						if(dat.code==1){ 
							 $(dat.data).each(function(index,bean){
							 	availableTags[index]=bean.value; 
							 	color_value_key[bean.value]=bean.id;
							 	color_key_value[bean.id]=bean.value;
							 });
						}
					}
			});  
		}
		
		var size_value_key = {};
		var size_key_value = {};
		loadSizeSpecification();
		function loadSizeSpecification() { 
		  	//async: false,
		    $.ajax({ 
					url : "${basePath}manager/Specification_specificationValueSearch",
					data : { 
						specificationName:'尺码'
					}, 
					dataType :"JSON",
					cache : false, 
					type : "POST", 
					success : function(dat){
						if(dat.code==1){ 
							 $(dat.data).each(function(index,bean){ 
							 	size_value_key[bean.value]=bean.id;
							 	size_key_value[bean.id]=bean.value;
							 });
						}
					}
			});  
		}
		
		
		
 
 
	$( "#add_color_input" ).autocomplete({
	     source: availableTags
	});  
		
	function MathRand(length) { 
		var num=""; 
		for(var i=0;i<length;i++) { 
			num+=Math.floor(Math.random()*10); 
		} 
		return num;
	} 
	
	//
	$('#save_product_list_btn').click(function(){ 
		save_product();
	});
	
	function save_product(){
		 
		var size_specification_arr  = $('.size_specification_div').get(); 
		var color_specification_arr = $('.color_specification_div').get(); 
		var size_specification_value_ids=new Array();
		var color_specification_value_ids=new Array();
		$(size_specification_arr).each(function(index,bean){
			size_specification_value_ids[index]=$(bean).attr('data-specification-value-id');
		});
		$(color_specification_arr).each(function(index,bean){
			color_specification_value_ids[index]=$(bean).attr('data-specification-value-id');
		});
		if(size_specification_value_ids.length<=0){
			return ;
		}
		if(color_specification_value_ids.length<=0){
			return ;
		}
		$("#save_product_list_btn").html("保存中...");
		
		$.ajax({ 
			url : "${basePath}manager/Product_saveProducts",
			data : { 
				sizeSpecificationValueIds:size_specification_value_ids,
				colorSpecificationValueIds:color_specification_value_ids,
				goodsId:'${(goods.id)?c}'
			}, 
			traditional:true,  
			dataType :"JSON",
			cache : false, 
			type : "POST", 
			async: false,
			success : function(dat){
				if(dat.code==1){ 
					 alert(dat.msg);
					 window.location.reload();
				}else {
					alert(dat.msg)
				}
				$("#save_product_list_btn").html("保存商品规格");
			}
		});  
		// traditional :true,  
			
	}
	
	//添加单个div按钮
	function addSingleProductDiv(){
			var randomLength = Date.parse(new Date())+MathRand(6);
			
			var html ='';
			html+='<div id="product_div_'+randomLength+'" class="bsp-alertdiv bsp-alertdiv-success" data-product-id=""  >';
			
			html+='<div class="input_name" style="height:32px;margin-bottom: 20px;">';
			html+='<span class="left_title" style="line-height: 32px;">条码：</span>';
			html+='<input type="text" name="barCode" class="search_text tdd50" style="width:210px" value="" /> ';
			html+='<button type="button"  class=" close close_product" data-parent-id="product_div_'+randomLength+'" data-dismiss="alert" aria-hidden="true" style="margin-right: 600px;float: right;    font-size: 50px;">×</button>';
			html+='</div>';
			
			html+='<div class="input_name" style="height:32px;margin-bottom: 20px;">';
			html+='<span class="left_title" style="line-height: 32px;">颜色：</span>';
			html+='<select name="color"   class="sp">';
			html+='<option value="">---</option>';
			html+='</select>';
			html+='</div>';
			
			html+='<div class="input_name" style="height:32px;margin-bottom: 20px;">';
			html+=' <span class="left_title" style="line-height: 32px;">尺码：</span>';
			html+=' <select name="size"   class="sp">';
			html+='<option value="">---</option>   ';
			html+='</select>';
			html+='</div>';
			
			
			html+=' <div class="input_name" style="height:32px;margin-bottom: 20px;">';
			html+=' <span class="left_title" style="line-height: 32px;">库存：</span>';
	        html+='<input type="text" name="stockCount" class="search_text tdd50" style="width:210px;" value="" /> ';
			html+='</div>';
			
			html+='<span class="tbl_btn" style="margin-left: 290px;"> ';
			html+='<span  type="button" class="bsp-btn bsp-btn-sm bsp-btn-primary" style="width: 100px;">保存</span> ';
			html+=' </span>';
			
			html+='</div>'; 
			
		    $('#div_product_list').append(html);
		    
		    //已经有的情况下保存
		    $('.close_product').unbind('click').click(function(){
		    	 var product_div_id =$(this).attr('data-parent-id');
		    	 var $product_div = $('#'+product_div_id);
		    	 var product_id=$product_div.attr("data-product-id");
		    	  
		    	 if(''==product_id){
		    	    $product_div.remove();
		    	 }else{
		    	 	//$product_div.remove();
		    	   	
		    	 }
		    }); 
	
	}
	

	

  
  $('#add_color_btn').click(function(){
   		var specificationValue=$('#add_color_input').val(); 
   		 
   		var spId    = color_value_key[specificationValue] ;
   		var spValue =  specificationValue;
   		if(null!=spId &&   'undefined'!=spId){
	   		 var html = '';
			 
			 var div_id = 'color_specification_div_'+spId;
			 
			 if($('#'+div_id).length>0){
			 	alert("已存在");
			    return ;
			 }
			 
			 var className ='color_specification';
			 
			 html+='<div id="'+div_id+'" class="bsp-alertdiv bsp-alertdiv-success dropzone_child '+className+'_div" data-specification-value-id="'+spId+'"  style=" margin-right: 10px;  width:120px; padding: 5px;">';
			 html+='<span>'+spValue+'</span>';
			 html+='<button type="button" class="close '+className+'" data-parent-id="'+div_id+'" data-dismiss="alert" aria-hidden="true">×</button>';
			 html+='</div>';
			 
			 $('#color_list_div').append(html);
			 
			 $('.'+className).unbind('click').click(function(){
			 	 var color_specification_div_id =$(this).attr('data-parent-id');
		 		 var $color_specification_div = $('#'+color_specification_div_id);
			 	 $color_specification_div.remove(); 
			 });
   		
   		} 
  	
  });
  
  

  
  
  	$('#add_size_btn').click(function(){ 
		var html='';
		var className ='size_specification';
		$('#size_list_temp_div div').each(function(index,bean){
			var spValue = $(bean).attr('data-sp-value'); 
			var spId    = size_value_key[spValue];
			var div_id = 'size_specification_div_'+spId;  
			if($('#'+div_id).length<=0){
				html+='<div id="'+div_id+'" class="bsp-alertdiv bsp-alertdiv-success dropzone_child '+className+'_div" data-specification-value-id="'+spId+'"  style=" margin-right: 10px;  width:120px; padding: 5px;">';
				html+='<span>'+spValue+'</span>';
				html+='<button type="button" class="close '+className+'" data-parent-id="'+div_id+'" data-dismiss="alert" aria-hidden="true">×</button>';
				html+='</div>';
			} 
		});
		 
		$('#size_list_temp_div').html('');
		
		$('#size_list_div').append(html);
		
		$('.'+className).unbind('click').click(function(){
			var size_specification_div_id =$(this).attr('data-parent-id');
		    var $size_specification_div = $('#'+size_specification_div_id);
			$size_specification_div.remove(); 
		});
		
	});
  
  

  
  

  /*
  $("#test_xiala").autocomplete({
   source: function( request, response ) {
    var keyWords=$.ui.autocomplete.escapeRegex( request.term );
    response( $.grep( DataSouce2(keyWords), function( item ){
     	return  item;
    }) );
   }
  });
  

  
  //利用ajax根据输入的到数据库查找 相当于
  function DataSouce2(keyWords) {
  		var mycars=new Array();
      	$.ajax({ 
			url : "${basePath}manager/Specification_specificationValueSearch",
			data : { 
				specificationName:'颜色',
				keyWords:keyWords
			}, 
			dataType :"JSON",
			cache : false, 
			type : "POST",
			async: false,
			success : function(dat){
				if(dat.code==1){ 
					 $(dat.data).each(function(index,bean){
					 	mycars[index]=bean.value; 
					 });
				}
			}
		});   
		return mycars;
  }
  */
	
 

	
	

});

</script>
</body>
</html>

